package com.zyh.stu.system.service.impl;

import com.zyh.stu.system.dao.impl.StudentDaoImpl;
import com.zyh.stu.system.domain.Student;
import com.zyh.stu.system.service.StudentService;

import java.util.ArrayList;

public class UserServiceImpl implements StudentService {
    public static final StudentDaoImpl daoImpl = new StudentDaoImpl();
    public static final ArrayList<Student> STU_LIST = StudentDaoImpl.STU_LIST;

    @Override
    public boolean add(Student student) {
        for (int i = 0; i < STU_LIST.size(); i++) {
            Student student1 = STU_LIST.get(i);
            if (student1.getSid().equals(student.getSid())) {
                System.out.println("您输入的编号重复了！");
                return false;
            }
        }
        daoImpl.add(student);
        System.out.println("添加成功！");
        daoImpl.findAll();
        return false;
    }

    @Override
    public boolean delete(String id) {
        int stuIndex = daoImpl.findById(id);
        if (stuIndex == -1) {
            System.out.println("您输入的编号不存在！");
            return false;
        }
        daoImpl.delete(id);
        System.out.println("删除成功！");
        daoImpl.findAll();
        return true;
    }

    @Override
    public boolean update(Student student) {
        daoImpl.update(student);
        daoImpl.findAll();
        return true;
    }

    @Override
    public void findAll() {
        daoImpl.findAll();
    }

    @Override
    public int findById(String id) {
        int stuIndex = daoImpl.findById(id);
        return stuIndex;
    }
}
